#include <xp/bas/search.h>
#include <xp/bas/stdio.h>

int compare (const void* x, const void* y, void* arg)
{
	if (*(int*)x > *(int*)y) return 1;
	if (*(int*)x < *(int*)y) return -1;
	return 0;
}

int xp_main ()
{

	int array[] = {1, 2, 3, 4, 5, 6, 7, 8, 9};
	int* x;
	int i;

	for (i = 0; i < 15; i++) {
		x = xp_bsearch (&i, array, 9, xp_sizeof(array[0]), XP_NULL, compare);
		if (x == XP_NULL) xp_printf (XP_TEXT("%d not found\n"), i);
		else xp_printf (XP_TEXT("%d found at %p (%d)\n"), i, x, *x);
	}

	return 0;
}

